﻿using Dapper;
using Entity;
using IRepository;
using System;
using System.Collections.Generic;
using System.Data;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Repository
{
    public class SysDictTypeRepository : ISysDictTypeRepository
    {
        private readonly string _connectionString;
        public SysDictTypeRepository(string connectionString)
        {
            _connectionString = connectionString;
        }

        public async Task<List<SysDictType>> GetAllNormalDictTypesAsync()
        {
            using (IDbConnection db  = new SqlConnection(_connectionString))
            {
                string sql = "select * from wms_Dictionary_type where Status = '0' order by DictTypeName ASC";
                return (await db.QueryAsync<SysDictType>(sql)).ToList();
            }
        }

        public async Task<SysDictType> GetDictTypeByCodeAsync(string dictTypeCode)
        {
            using (IDbConnection db = new SqlConnection(_connectionString))
            {
                string sql = "select * from wms_Dictionary_type where  DictTypeCode = @DictTypeCode AND Status = '0'";
                return await db.QueryFirstOrDefaultAsync<SysDictType>(sql, new { DictTypeCode = dictTypeCode });
            }
        }
    }
}
